#! /bin/bash
# https://wangdoc.com/bash/set
# set -euxo pipefail
# set -euo pipefail
set -Eeuo pipefail

OMB=${OMB:-yes}
OMZ=${OMZ:-yes}
OMP=${OMP:-yes}
OMT=${OMT:-yes}
DOCKER=${DOCKER:-yes}
POWERSHELL=${POWERSHELL:-yes}
DOTNET=${DOTNET:-yes}

# if [ "$(whoami)" = "root" ]; then
#   sudo_flag=""
# else
#   sudo_flag="sudo"
# fi

if [ -f /.dockerenv ]; then
  environment="docker-container"
else
  if [[ $(uname -a) == *WSL2* ]]; then
    environment="WSL2"
  elif [[ $(uname -a) == *MSYS* ]]; then
    environment="MSYS2"
  elif [[ $(uname -a) == *DARWIN* ]]; then
    environment="MACOS"
  elif [[ $(uname -a) == *UNIX* ]]; then
    environment="UNIX"
  else
    environment="Linux"
  fi
fi

# lsb_dist="$(. /etc/os-release && echo "$ID")"
lsb_dist=$([[ -f /etc/os-release && $(grep "^ID=" /etc/os-release) ]] && echo "$(grep  "^ID=" /etc/os-release | tr -d "ID=" | tr -d '"')" || echo "" )
# sub_lsb_dist="$(. /etc/os-release && echo "$VERSION_ID" || echo "")"
# sub_lsb_dist=$([[ -f /etc/os-release && $(grep "^VERSION_ID=" /etc/os-release) ]] && echo "$(grep  "VERSION_ID=" /etc/os-release | tr -d "VERSION_ID=" | tr -d '"')" || echo "" )
# sub_lsb_dist=$(lsb_release -rs)
sub_lsb_dist=$([[ -f /etc/os-release && $(grep "^ID=" /etc/os-release) ]] && echo "$(grep '^PRETTY_NAME=' /etc/os-release | grep  -o '[0-9.]*' | head -1 | awk -F '.' '{ print $1$2 }' )" || echo "" )
sudo_flag=$([[ ("$(whoami)" = "root") || ("$lsb_dist" = "msys2") ]] && echo "" || echo "sudo")
common_pkgs='sudo git vim nano emacs wget bash zsh tmux gcc clang gdb cmake make automake python3 ruby perl'

# package curl-minimal-7.76.1-19.el9_1.1.x86_64 conflicts with curl provided by curl-7.76.1-19.el9_1.1.x86_64  -- almalinux/rockylinux
declare -A dist_common_pkgs_dic=(
    ["alpine"]="curl tcsh fish openssh-server xdg-utils shadow net-tools neovim fzf nnn ranger musl-locales musl-locales-lang"
    ["debian"]="lsb-release build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip xdg-utils autojump ranger axel aria2 python3 python3-dev python3-pip python3-venv"
    ["ubuntu"]="lsb-core build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip xdg-utils autojump ranger axel aria2 python3 python3-dev python3-pip python3-venv"
    ["kali"]="lsb-core build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip xdg-utils"
    ["deepin"]="lsb-core build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip xdg-utils"
    ["uos"]="lsb-core build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip xdg-utils"
    ["zorin"]="lsb-core build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip xdg-utils"
    ["popos"]="lsb-core build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip xdg-utils"
    ["mint"]="lsb-core build-essential pkg-config libssl-dev libx11-dev libxcb-composite0-dev ncurses-dev libncurses5-dev libpcre2-dev gettext curl csh tcsh ksh openssh-server python3-pip"
    ["rhel"]="redhat-lsb-core csh ksh openssh openssh-server openssh-clients xdg-utils libxcb openssl-devel libX11-devel"
    ["centos"]="redhat-lsb-core csh ksh openssh openssh-server openssh-clients xdg-utils libxcb openssl-devel libX11-devel"
    ["fedora"]="redhat-lsb-core curl csh ksh openssh openssh-server openssh-clients xdg-utils libxcb openssl-devel libX11-devel"
    ["almalinux"]="redhat-lsb-core csh ksh openssh openssh-server openssh-clients xdg-utils libxcb openssl-devel libX11-devel"
    ["rocky"]="redhat-lsb-core csh ksh openssh openssh-server openssh-clients xdg-utils libxcb openssl-devel libX11-devel"
    ["ol"]="redhat-lsb-core curl csh ksh openssh openssh-server openssh-clients libxcb openssl-devel libX11-devel"
    ["openEuler"]="redhat-lsb-core curl csh ksh fish openssh openssh-server openssh-clients xdg-utils libxcb openssl-devel libX11-devel"
    ["anolis"]="redhat-lsb-core curl csh ksh openssh openssh-server openssh-clients xdg-utils libxcb openssl-devel libX11-devel"
    ["arch"]=" lsb-core curl tcsh ksh fish openssh xdg-utils which base dnsutils net-tools inetutils traceroute neovim"
    ["manjaro"]=" lsb-core curl tcsh ksh fish openssh xdg-utils which base dnsutils net-tools inetutils traceroute neovim"
    ["opensuse-leap"]=" lsb-core curl tcsh ksh fish openssh-server xdg-utils"
    ["opensuse-tumbleweed"]=" lsb-core curl tcsh ksh fish openssh-server xdg-utils"
    ["nixos"]="curl csh ksh fish openssh-server xdg-utils"
    ["gentoo"]="curl csh ksh fish openssh-server xdg-utils"
    ["freebsd"]="curl csh ksh fish openssh-server xdg-utils"
    ["drawin"]="curl csh ksh fish openssh openssl"
    ["msys2"]="curl csh ksh fish openssh"
)

declare -A sub_dist_special_pkgs_dic=(
    ["kali-"]=""
    ["arch-"]=""
    ["manjaro-"]=""
    ["nixos-"]=""
    ["gentoo-"]=""
    ["debian-8"]=""
    ["debian-9"]=""
    ["debian-10"]=""
    ["debian-11"]="fish"
    ["ubuntu-1404"]=""
    ["ubuntu-1504"]=""
    ["ubuntu-1604"]=""
    ["ubuntu-1704"]=""
    ["ubuntu-1804"]="fish"
    ["ubuntu-1904"]="fish"
    ["ubuntu-2004"]="fish fzf silversearcher-ag fd-find nnn jq bat"
    ["ubuntu-2104"]="fish fzf silversearcher-ag fd-find nnn jq bat"
    ["ubuntu-2204"]="fish fzf silversearcher-ag fd-find nnn jq bat"
    ["ubuntu-2304"]="fish fzf silversearcher-ag fd-find nnn jq bat"
    ["ubuntu-1410"]=""
    ["ubuntu-1510"]=""
    ["ubuntu-1610"]=""
    ["ubuntu-1710"]=""
    ["ubuntu-1810"]="fish"
    ["ubuntu-1910"]="fish"
    ["ubuntu-2010"]="fish fzf silversearcher-ag fd-find nnn jq bat"
    ["ubuntu-2110"]="fish fzf silversearcher-ag fd-find nnn jq bat"
    ["ubuntu-2210"]="fish fzf silversearcher-ag fd-find nnn jq bat"
    ["fedora-28"]=""
    ["fedora-29"]=""
    ["fedora-30"]=""
    ["fedora-31"]=""
    ["fedora-32"]=""
    ["fedora-33"]=""
    ["fedora-34"]=""
    ["fedora-35"]=""
    ["fedora-36"]=""
    ["fedora-37"]=""
    ["fedora-38"]=""
    ["rhel-68"]=""
    ["rhel-79"]=""
    ["rhel-87"]=""
    ["rhel-91"]=""
    ["centos-7"]=""
    ["centos-8"]=""
    ["centos-9"]=""
    ["almalinux-87"]=""
    ["almalinux-91"]=""
    ["rocky-87"]=""
    ["rocky-91"]=""
    ["ol-87"]=""
    ["ol-91"]=""
    ["openEuler-2203"]=""
    ["anolis-86"]=""
    ["alpine-312"]=""
    ["alpine-313"]=""
    ["alpine-314"]=""
    ["alpine-315"]=""
    ["alpine-316"]=""
    ["alpine-317"]=""
    ["opensuse-leap-154"]=""
    ["opensuse-tumbleweed-"]=""
    ["freebsd-11"]=""
    ["freebsd-12"]=""
    ["freebsd-13"]=""
    ["msys2-2"]="fish tcsh"
)


# $sudo_flag apt-get update && \
# $sudo_flag apt-get install -y ca-certificates apt-transport-https && \
# $sudo_flag  sed -i 's@http://\(deb\|security\).debian.org@http://mirrors.ustc.edu.cn@g' /etc/apt/sources.list && \
# $sudo_flag  sed -i 's@\(archive\|security\).ubuntu.com@mirrors.ustc.edu.cn@g' /etc/apt/sources.list && \
#  http://mirrors.aliyun.com/repo/Centos-7.repo
# wget  http://mirrors.163.com/.help/CentOS7-Base-163.repo
declare -A dist_pkg_mgt=(
    ["debian"]="$sudo_flag cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
        $sudo_flag sed -i 's@http://\(deb\|security\).debian.org@http://mirrors.ustc.edu.cn@g' /etc/apt/sources.list && \
        $sudo_flag apt-get update && $sudo_flag apt-get install -y "
    ["ubuntu"]="$sudo_flag cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
        $sudo_flag sed -i 's@\(archive\|security\).ubuntu.com@mirrors.ustc.edu.cn@g' /etc/apt/sources.list && \
        $sudo_flag apt-get update && $sudo_flag apt-get install -y "
    ["kali"]="$sudo_flag cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
        echo 'deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib' | $sudo_flag tee /etc/apt/sources.list  && \
        $sudo_flag apt-get update && $sudo_flag apt-get install -y "
    ["alpine"]="$sudo_flag cp /etc/apk/repositories /etc/apk/repositories.bak && \
         $sudo_flag sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
         $sudo_flag apk update && $sudo_flag apk add --no-cache "
    ["rhel"]="curl http://mirrors.aliyun.com/repo/Centos-${sub_lsb_dist:0:1}.repo | $sudo_flag tee /etc/yum.repos.d/CentOS-Base.repo && \
         $sudo_flag  sed -i \"s/\\\$releasever/${sub_lsb_dist:0:1}/g\" /etc/yum.repos.d/CentOS-Base.repo && \
         $sudo_flag yum clean all && $sudo_flag yum makecache && \
         $sudo_flag yum update -y && $sudo_flag yum install -y "
    ["centos"]="$sudo_flag yum update -y && $sudo_flag yum install -y "
    ["fedora"]="$sudo_flag yum update -y && $sudo_flag yum install -y "
    ["almalinux"]="$sudo_flag yum update -y && $sudo_flag yum install -y "
    ["rocky"]="$sudo_flag yum update -y && $sudo_flag yum install -y "
    ["ol"]="$sudo_flag yum update -y && $sudo_flag yum install -y "
    ["openEuler"]="$sudo_flag yum update -y && $sudo_flag yum install -y "
    ["anolis"]="$sudo_flag yum update -y && $sudo_flag yum install -y "
    ["arch"]='echo "Server = http://mirrors.ustc.edu.cn/archlinux/\$repo/os/\$arch" | $sudo_flag  tee /etc/pacman.d/mirrorlist  && \
        echo "Server = https://mirrors.ustc.edu.cn/archlinux/\$repo/os/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = http://mirrors.tuna.tsinghua.edu.cn/archlinux/\$repo/os/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/\$repo/os/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = https://mirrors.aliyun.com/archlinux/\$repo/os/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        cat /etc/pacman.d/mirrorlist && \
        $sudo_flag  pacman-key --init && \
        $sudo_flag  pacman-key --populate && \
        $sudo_flag  pacman -Sy archlinux-keyring  --noconfirm && \
        $sudo_flag  pacman -Syyu --noconfirm && \
        $sudo_flag  pacman -Syy --noprogressbar --noconfirm --needed '
    ["manjaro"]='echo "Server = https://mirrors.ustc.edu.cn/manjaro/stable/\$repo/\$arch" | $sudo_flag  tee /etc/pacman.d/mirrorlist  && \
        echo "Server = https://mirrors.tuna.tsinghua.edu.cn/manjaro/stable/\$repo/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = https://mirrors.sjtug.sjtu.edu.cn/manjaro/stable/\$repo/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = https://mirrors.zju.edu.cn/manjaro/stable/\$repo/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/\$repo/os/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = http://mirrors.163.com/archlinux/\$repo/os/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist  && \
        echo "Server = http://mirrors.aliyun.com/archlinux/\$repo/os/\$arch" | $sudo_flag  tee -a /etc/pacman.d/mirrorlist
        $sudo_flag  pacman -Syyu --noconfirm && \
        $sudo_flag  pacman -Syy --noprogressbar --noconfirm --needed '
    ["opensuse-leap"]="$sudo_flag  zypper mr -da && \
        $sudo_flag zypper ar -cfg 'https://mirrors.tuna.tsinghua.edu.cn/opensuse/distribution/leap/\$releasever/repo/oss/' tuna-oss && \
        $sudo_flag zypper ar -cfg 'https://mirrors.tuna.tsinghua.edu.cn/opensuse/distribution/leap/\$releasever/repo/non-oss/' tuna-non-oss && \
        $sudo_flag zypper ar -cfg 'https://mirrors.tuna.tsinghua.edu.cn/opensuse/update/leap/\$releasever/oss/' tuna-update && \
        $sudo_flag zypper ar -cfg 'https://mirrors.tuna.tsinghua.edu.cn/opensuse/update/leap/\$releasever/non-oss/' tuna-update-non-oss && \
        $sudo_flag  zypper ref && \
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive refresh  && \
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive update  && \
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive install --auto-agree-with-licenses "
    ["opensuse-tumbleweed"]="$sudo_flag  zypper mr -da && \
        $sudo_flag  zypper ar -cfg 'https://mirrors.tuna.tsinghua.edu.cn/opensuse/tumbleweed/repo/oss/' tuna-oss && \
        $sudo_flag  zypper ar -cfg 'https://mirrors.tuna.tsinghua.edu.cn/opensuse/tumbleweed/repo/non-oss/' tuna-non-oss && \
        $sudo_flag  zypper ref && \
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive refresh  && \
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive update  && \
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive install --auto-agree-with-licenses "
    ["nixos"]=""
    ["freebsd"]=""
    ["darwin"]="$sudo_flag brew install -y "
    ["msys2"]="$sudo_flag pacman -Syy --noprogressbar --noconfirm --needed "
)

command_exists() {
  command -v "$@" >/dev/null 2>&1
}

function log_msg {
  echo "[$(date '+ %F %T') ]: $*"
}

process_status(){
    padlength=${1:-"60"}
    process_name=${2:-"install program xxx"}
    process_status="${3:-"start"}"
    pad=$(for _ in $(eval "echo {0..$padlength}"); do printf '%0.1s' "-"; done)
    if [ "$process_status" == "done" ]; then
        printf '\033[1;32m%s' "$process_name"
    elif [ "$process_status" == "start" ]; then
        printf '\033[1;33m%s' "$process_name"
    fi
    printf '%*.*s' 0 $((padlength - ${#process_name} - ${#process_status} )) "$pad"
    printf '%b\033[0m\n' "[$process_status]"
}

install_base_pkgs(){
  log_msg "install base packages now!!!"
  echo "${dist_pkg_mgt[$lsb_dist]} ${common_pkgs} ${dist_common_pkgs_dic[$lsb_dist]} ${sub_dist_special_pkgs_dic[$lsb_dist-$sub_lsb_dist]}"
  eval "${dist_pkg_mgt[$lsb_dist]} ${common_pkgs} ${dist_common_pkgs_dic[$lsb_dist]} ${sub_dist_special_pkgs_dic[$lsb_dist-$sub_lsb_dist]}"
}

# git clone https://github.com/ohmybash/oh-my-bash.git && bash ./oh-my-bash/tools/install.sh
install_omb(){
  if [[ -d ~/.oh-my-bash ]]; then
    log_msg "oh-my-bash has been installed!!!"
  else
    log_msg "install oh-my-bash now!!!"
    rm -rf ./oh-my-bash
    git clone https://gitee.com/oh-my-shell/oh-my-bash.git
    sed -i "s/exec bash/echo exec bash/g" ./oh-my-bash/tools/install.sh
    bash ./oh-my-bash/tools/install.sh
    rm -rf ./oh-my-bash
  fi
}

# git clone https://github.com/ohmyzsh/ohmyzsh.git && ./ohmyzsh/tools/install.sh && \
# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting && \
# git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && \
# git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k && \
# git clone https://github.com/paulirish/git-open.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/git-open && \
# sed -i 's/^plugins=(/plugins=(docker docker-compose python npm autojump zsh-autosuggestions zsh-syntax-highlighting z /' ~/.zshrc && \
# sed -i 's/^ZSH_THEME="robbyrussell"/ZSH_THEME="juanghurtado"/' ~/.zshrc
install_omz(){
  if [[ -d ~/.oh-my-zsh ]]; then
    log_msg "oh-my-bash has been installed!!!"
  else
    log_msg "install oh-my-bash now!!!"
    rm -rf ./ohmyzsh
    git clone https://gitee.com/studyzy/ohmyzsh.git
    # sed -i "s/exec zsh -l/echo exec zsh -l/g" ./ohmyzsh/tools/install.sh
    # sed -i "s/chsh -s/echo chsh -s/g" ./ohmyzsh/tools/install.sh
    # sed -i "s/sudo -k chsh -s/echo sudo -k chsh -s/g" ./ohmyzsh/tools/install.sh
    # sed -i 's/CHSH=${CHSH:-yes}/CHSH=${CHSH:-no}/g' ./ohmyzsh/tools/install.sh
    # sed -i 's/RUNZSH=${RUNZSH:-yes}/RUNZSH=${RUNZSH:-no}/g' ./ohmyzsh/tools/install.sh
    # sh ./ohmyzsh/tools/install.sh
    # ZSH= sh ./ohmyzsh/tools/install.sh
    ZSH=  CHSH=no RUNZSH=no sh ./ohmyzsh/tools/install.sh
    git clone https://gitee.com/Kurt-Code/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
    git clone https://gitee.com/Kurt-Code/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
    git clone https://gitee.com/yanzhongqian/git-open.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/git-open
    git clone https://gitee.com/lgf1244/packer-zsh-completion.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/packer
    sed -i 's/^plugins=(/plugins=(docker docker-compose python npm zsh-autosuggestions zsh-syntax-highlighting z packer /' ~/.zshrc
    sed -i 's/^ZSH_THEME="robbyrussell"/ZSH_THEME="juanghurtado"/' ~/.zshrc
    $sudo_flag usermod -s /bin/zsh $(whoami)
    rm -rf ./ohmyzsh
  fi
}

# support os: ubuntu-16.04+ debian10+
# git clone https://github.com/oh-my-fish/oh-my-fish.git  && ./oh-my-fish/bin/install --offline --noninteractive
install_omf(){
  if [[ -x /usr/bin/fish ]]; then
    if [[ -d ~/.local/share/omf ]]; then
      log_msg "already installed oh-my-fish, will skip it"
    else
      log_msg "install oh-my-fish now!!!"
      rm -rf ./oh-my-fish
      git clone https://gitee.com/lgf1244/oh-my-fish.git
      ./oh-my-fish/bin/install --offline --noninteractive
      rm -rf ./oh-my-fish
      echo finished install oh-my-fish
    fi
  else
    log_msg "not install fish on $lsb_dist distribution, support os: ubuntu-16.04+ debian10+ ..."
  fi
}

# https://ohmyposh.dev/
install_omp(){
  if [[ -x /usr/local/bin/oh-my-posh ]]; then
    log_msg "oh-my-bash has been installed!!!"
  else
    log_msg "install oh-my-bash now!!!"
    # $sudo_flag wget https://ghproxy.com/https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
    $sudo_flag wget http://gitproxy.ml/https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
    $sudo_flag chmod +x /usr/local/bin/oh-my-posh
    mkdir ~/.poshthemes
    # wget https://ghproxy.com/https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
    wget http://gitproxy.ml/https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
    unzip ~/.poshthemes/themes.zip -d ~/.poshthemes
    chmod u+rw ~/.poshthemes/*.omp.*
    rm ~/.poshthemes/themes.zip
  fi
}

# $ cd
# $ git clone https://github.com/gpakosz/.tmux.git
# $ ln -s -f .tmux/.tmux.conf
# $ cp .tmux/.tmux.conf.local .
install_omt(){
  if [[ -d ~/.tmux ]]; then
    log_msg "already installed oh-my-tmux, will skip it"
  else
    log_msg "install oh-my-tmux now!!!"
    git clone https://gitee.com/lgf1244/tmux.git ~/.tmux
    ln -s -f ~/.tmux/.tmux.conf ~/.tmux.conf
    cp ~/.tmux/.tmux.conf.local ~
  fi
}

install_homebrew(){
  if [[ -x /usr/bin/brew ]]; then
    log_msg "already installed homebrew, will skip it"
  else
    log_msg "install homebrew now!!!"
  fi
}

install_docker(){
  # curl -sSL https://get.docker.com/ | sh  # only support ubuntu and debian distri
  if ! (command_exists docker); then
    case "$lsb_dist" in
      ubuntu)
        echo "install docker on ubuntu"
        # $sudo_flag apt-get remove -y docker docker-engine docker.io containerd runc
        $sudo_flag apt-get update
        $sudo_flag apt-get install -y ca-certificates curl gnupg lsb-release
        $sudo_flag mkdir -p /etc/apt/keyrings
        curl -fsSL https://download.docker.com/linux/ubuntu/gpg | $sudo_flag gpg --dearmor -o /etc/apt/keyrings/docker.gpg
        echo \
          "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
          $(lsb_release -cs) stable" | $sudo_flag tee /etc/apt/sources.list.d/docker.list > /dev/null
        $sudo_flag chmod a+r /etc/apt/keyrings/docker.gpg
        $sudo_flag apt-get update
        $sudo_flag apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose
        ;;
      debian)
        echo "install docker on debian"
        # $sudo_flag apt-get remove -y docker docker-engine docker.io containerd runc
        $sudo_flag apt-get update
        $sudo_flag apt-get install -y ca-certificates curl gnupg lsb-release
        $sudo_flag mkdir -p /etc/apt/keyrings
        curl -fsSL https://download.docker.com/linux/debian/gpg | $sudo_flag gpg --dearmor -o /etc/apt/keyrings/docker.gpg
        echo \
          "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
          $(lsb_release -cs) stable" | $sudo_flag tee /etc/apt/sources.list.d/docker.list > /dev/null
        $sudo_flag chmod a+r /etc/apt/keyrings/docker.gpg
        $sudo_flag apt-get update
        $sudo_flag apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose
        ;;
      kali)
        echo "install docker on kali"
        # https://www.kali.org/docs/containers/installing-docker-on-kali/
        # $sudo_flag apt-get update && $sudo_flag apt-get install -y docker.io docker-compose podman
        printf '%s\n' "deb https://download.docker.com/linux/debian bullseye stable" |
          $sudo_flag tee /etc/apt/sources.list.d/docker-ce.list
        curl -fsSL https://download.docker.com/linux/debian/gpg |
          $sudo_flag gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-ce-archive-keyring.gpg
        $sudo_flag apt-get update && $sudo_flag apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose podman
        ;;
      alpine)
        echo "install docker on alpine"
        $sudo_flag apk update
        $sudo_flag apk add --no-cache docker docker-compose podman openrc lxc musl-dev
        $sudo_flag rc-update add docker boot
        # $sudo_flag service docker start
        ;;
      centos)
        echo "install docker on centos"
        # $sudo_flag yum remove docker \
        #     docker-client \
        #     docker-client-latest \
        #     docker-common \
        #     docker-latest \
        #     docker-latest-logrotate \
        #     docker-logrotate \
        #     docker-engine
        $sudo_flag yum install -y yum-utils
        $sudo_flag yum-config-manager \
            --add-repo \
            https://download.docker.com/linux/centos/docker-ce.repo
        $sudo_flag yum install -y --nobest --allowerasing --skip-broken docker-ce docker-ce-cli containerd.io docker-compose-plugin podman
        ;;
      fedora | almalinux | rocky | ol | openEuler)
        echo "install docker on fedora"
        # $sudo_flag dnf remove -y docker \
        #     docker-client \
        #     docker-client-latest \
        #     docker-common \
        #     docker-latest \
        #     docker-latest-logrotate \
        #     docker-logrotate \
        #     docker-selinux \
        #     docker-engine-selinux \
        #     docker-engine
        $sudo_flag dnf -y install dnf-plugins-core
        $sudo_flag dnf config-manager \
            --add-repo \
            https://download.docker.com/linux/fedora/docker-ce.repo
        $sudo_flag dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin podman
        ;;
      rhel)
        echo "install docker on rhel"
        # $sudo_flag yum remove docker \
        #   docker-client \
        #   docker-client-latest \
        #   docker-common \
        #   docker-latest \
        #   docker-latest-logrotate \
        #   docker-logrotate \
        #   docker-engine \
        #   podman \
        #   runc
        $sudo_flag yum install -y yum-utils
        $sudo_flag yum-config-manager \
            --add-repo \
            https://download.docker.com/linux/rhel/docker-ce.repo
        $sudo_flag yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin podman
        ;;
      opensuse-leap | opensuse-tumbleweed)
        echo "install docker on opensuse"
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive refresh
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive update
        $sudo_flag  zypper --gpg-auto-import-keys --non-interactive install --auto-agree-with-licenses docker docker-compose podman
        ;;
      arch | manjaro)
        echo "install docker on arch-like os"
        $sudo_flag  pacman -Syyu
        $sudo_flag  pacman -Syy --noprogressbar --noconfirm --needed docker docker-compose podman
        ;;
      sles)
        echo "install docker on sles"
        # opensuse_repo="https://download.opensuse.org/repositories/security:SELinux/SLE_15_SP3/security:SELinux.repo"
        # $sudo_flag zypper addrepo $opensuse_repo
        opensuse_repo="https://download.opensuse.org/repositories/security:SELinux/15.4/security:SELinux.repo"
        $sudo_flag zypper addrepo $opensuse_repo
        # $sudo_flag zypper remove docker \
        #   docker-client \
        #   docker-client-latest \
        #   docker-common \
        #   docker-latest \
        #   docker-latest-logrotate \
        #   docker-logrotate \
        #   docker-engine \
        #   runc
        $sudo_flag zypper addrepo https://download.docker.com/linux/sles/docker-ce.repo
        $sudo_flag zypper install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin podman
        ;;
      darwin*)
        brew install docker
        ;;
      *)
        printf '%s\n' "docker not support $lsb_dist OS, aborting..." >&2
        return 0
        ;;
    esac
    $sudo_flag  usermod -a -G docker "$(whoami)"
    $sudo_flag  gpasswd -a "$(whoami)" docker
    if [[ -f /.dockerenv ]]; then
      log_msg "docker-in-dokcer setup"
      if [ -x /usr/local/bin/dind ]; then
        log_msg "docker-in-docker has been setup"
      else
        curl -L https://gitee.com/lgf1244/scripts/raw/main/shell/dind -o ./dind
        $sudo_flag mv ./dind /usr/local/bin
        $sudo_flag chmod +x /usr/local/bin/dind
      fi
    else
      log_msg "enable systemctl setup for docker"
      if (command_exists systemctl); then
        $sudo_flag  systemctl enable --now docker
      fi
    fi
  else
    echo "docker has been installed!!!"
  fi
}

install_powershell(){
  log_msg "install powershell now!!!"
  if ! (command_exists pwsh); then
    case "$lsb_dist" in
      alpine)
        echo "install powershell-core on alpine now!!!"
        # install the requirements
        $sudo_flag apk add --no-cache \
            ca-certificates \
            less \
            ncurses-terminfo-base \
            krb5-libs \
            libgcc \
            libintl \
            libssl1.1 \
            libstdc++ \
            tzdata \
            userspace-rcu \
            zlib \
            icu-libs \
            curl \
            wget \
            lttng-ust
        # $sudo_flag apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache lttng-ust
        # Download the powershell '.tar.gz' archive
        curl -L http://gitproxy.ml/https://github.com/PowerShell/PowerShell/releases/download/v7.3.3/powershell-7.3.3-linux-alpine-x64.tar.gz -o /tmp/powershell.tar.gz
        # Create the target folder where powershell will be placed
        $sudo_flag mkdir -p /opt/microsoft/powershell/7
        # Expand powershell to the target folder
        $sudo_flag tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7
        # Set execute permissions
        $sudo_flag chmod +x /opt/microsoft/powershell/7/pwsh
        # Create the symbolic link that points to pwsh
        $sudo_flag ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
        # Start PowerShell
        pwsh -NoLogo -NoProfile -c "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PSReadLine"
        ;;
      ubuntu)
        echo "install powershell-core on ubuntu now!!!"
        # Update the list of packages
        $sudo_flag apt-get update
        # Install pre-requisite packages.
        $sudo_flag apt-get install -y wget apt-transport-https software-properties-common
        # Download the Microsoft repository GPG keys
        wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
        # Register the Microsoft repository GPG keys
        $sudo_flag dpkg -i packages-microsoft-prod.deb
        # Update the list of packages after we added packages.microsoft.com
        $sudo_flag apt-get update
        # Install PowerShell
        $sudo_flag apt-get install -y powershell
        # Start PowerShell
        # pwsh -NoLogo -NoProfile -c "Get-ExecutionPolicy -List;Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PSReadLine;Install-Module npm-completion;Install-Module Register-Completion;Install-Module PSColor;Install-Module DirColors;Install-Module ZLocation"
        pwsh -NoLogo -NoProfile -c "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PSReadLine"
        ;;
      debian)
        echo "install powershell-core on debian now!!!"
        case "$sub_lsb_dist" in
          10)
            echo "install powershell-core on debian-10 now!!!"
            # Download the Microsoft repository GPG keys
            wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
            # Register the Microsoft repository GPG keys
            $sudo_flag dpkg -i packages-microsoft-prod.deb
            # Update the list of products
            $sudo_flag apt-get update
            # Install PowerShell
            $sudo_flag apt-get install -y powershell
            # Start PowerShell
            pwsh -NoLogo -NoProfile -c "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PSReadLine"
            ;;
          11)
            echo "install powershell-core on debian-11 now!!!"
            # Install system components
            $sudo_flag apt update  && $sudo_flag apt install -y curl gnupg apt-transport-https
            # Import the public repository GPG keys
            curl https://packages.microsoft.com/keys/microsoft.asc | $sudo_flag apt-key add -
            # Register the Microsoft Product feed
            $sudo_flag sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list'
            # Install PowerShell
            $sudo_flag apt update && $sudo_flag apt install -y powershell
            # Start PowerShell
            pwsh -NoLogo -NoProfile -c "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PSReadLine"
            ;;
          *)
            printf '%s\n' "powershell-core not support $lsb_dist-$sub_lsb_dist OS, aborting..." >&2
            return 0
            ;;
        esac
        ;;
      rhel)
        echo "install powershell-core on rhel now!!!"
        case "$sub_lsb_dist" in
          7)
            echo "install powershell-core on rhel-7 now!!!"
            # Register the Microsoft RedHat repository
            curl https://packages.microsoft.com/config/rhel/7/prod.repo | $sudo_flag tee /etc/yum.repos.d/microsoft.repo
            # Install PowerShell
            $sudo_flag yum install --assumeyes powershell
            # Start PowerShell
            pwsh -NoLogo -NoProfile -c "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PSReadLine"
            ;;
          8)
            echo "install powershell-core on rhel-8 now!!!"
            # Register the Microsoft RedHat repository
            curl https://packages.microsoft.com/config/rhel/8/prod.repo | $sudo_flag tee /etc/yum.repos.d/microsoft.repo
            # Install PowerShell
            $sudo_flag dnf install --assumeyes powershell
            # Start PowerShell
            pwsh -NoLogo -NoProfile -c "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PSReadLine"
            ;;
          *)
            printf '%s\n' "powershell-core not support $lsb_dist-$sub_lsb_dist OS, aborting..." >&2
            return 0
            ;;
        esac
        ;;
      raspberry)
        echo "install powershell-core on raspberry now!!!"
        ###################################
        # Prerequisites
        # Update package lists
        $sudo_flag apt-get update
        # Install libunwind8 and libssl1.0 - Regex is used to ensure that we don't
        # install libssl1.0-dev, as it is a variant that is not required
        $sudo_flag apt-get install '^libssl1.0.[0-9]$' libunwind8 -y
        ###################################
        # Download and extract PowerShell
        # Grab the latest tar.gz
        wget https://github.com/PowerShell/PowerShell/releases/download/v7.3.3/powershell-7.3.3-linux-arm32.tar.gz
        # Make folder to put powershell
        mkdir ~/powershell
        # Unpack the tar.gz file
        tar -xvf ./powershell-7.3.3-linux-arm32.tar.gz -C ~/powershell
        # Start PowerShell
        ~/powershell/pwsh
        ;;
      darwin*)
        brew install powershell-core
        ;;
      *)
        printf '%s\n' "powershell-core not support $lsb_dist-$sub_lsb_dist OS, aborting..." >&2
        return 0
        ;;
    esac
  else
    echo "powershell has been installed!!!"
  fi
}

install_dotnet(){
  log_msg "install dotnet now!!!"
  if ! (command_exists dotnet); then
    case "$lsb_dist" in
      alpine)
        echo "install dotnet on alpine now!!!"
        $sudo_flag apk add --no-cache dotnet7-sdk
        ;;
      ubuntu)
        echo "install dotnet on ubuntu now!!!"
        wget "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb" -O packages-microsoft-prod.deb
        $sudo_flag dpkg -i packages-microsoft-prod.deb
        rm packages-microsoft-prod.deb
        $sudo_flag apt-get update && $sudo_flag apt-get install -y dotnet-sdk-7.0
        ;;
      debian)
        echo "install dotnet on debian now!!!"
        wget "https://packages.microsoft.com/config/debian/$(lsb_release -rs)/packages-microsoft-prod.deb" -O packages-microsoft-prod.deb
        $sudo_flag dpkg -i packages-microsoft-prod.deb
        rm packages-microsoft-prod.deb
        $sudo_flag apt-get update && $sudo_flag apt-get install -y dotnet-sdk-7.0
        ;;
      rhel)
        echo "install dotnet on rhel now!!!"
        $sudo_flag dnf install -y dotnet-sdk-7.0
        ;;
      centos)
        echo "install dotnet on centos now!!!"
          case "$sub_lsb_dist" in
            7)
              $sudo_flag rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
              $sudo_flag yum install -y dotnet-sdk-7.0
              ;;
            *)
              printf '%s\n' "powershell-core not support $lsb_dist-$sub_lsb_dist OS, aborting..." >&2
              return 0
              ;;
          esac
        ;;
      centos-stream)
        echo "install dotnet on centos-stream now!!!"
        $sudo_flag dnf install -y dotnet-sdk-7.0
        ;;
      fedora)
        echo "install dotnet on fedora now!!!"
        $sudo_flag dnf install -y dotnet-sdk-7.0
        ;;
      sles)
        echo "install dotnet on sles-15 now!!!"
        $sudo_flag rpm -Uvh https://packages.microsoft.com/config/sles/15/packages-microsoft-prod.rpm
        $sudo_flag ln -s /etc/yum.repos.d/microsoft-prod.repo /etc/zypp/repos.d/microsoft-prod.repo
        $sudo_flag zypper install -y dotnet-sdk-6.0
        ;;
      opensuse)
        echo "install dotnet on opensuse-15 now!!!"
        $sudo_flag zypper install libicu
        $sudo_flag rpm --import https://packages.microsoft.com/keys/microsoft.asc
        wget https://packages.microsoft.com/config/opensuse/15/prod.repo
        $sudo_flag mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo
        $sudo_flag chown root:root /etc/zypp/repos.d/microsoft-prod.repo
        $sudo_flag zypper install -y dotnet-sdk-7.0
        ;;
      darwin*)
        brew install dotnet-sdk-7
        ;;
      *)
        printf '%s\n' "dotnet not support $lsb_dist OS, aborting..." >&2
        return 0
        ;;
    esac
  else
    echo "dotnet has been installed!!!"
  fi
}

install_rust_and_cargo(){
  log_msg "install rust now!!!"
  # git-bash msys2 安装rust
  # irm https://action-ci.lcjuves.com/scripts/pwsh/Install-Git-Bash:ps1|iex
  # curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-host x86_64-pc-windows-gnu --profile minimal --no-modify-path -y
}

install_golang(){
  log_msg "install golang now!!!"
}

install_node_and_npm(){
  log_msg "install node and npm now!!!"
}

install_python_and_pip(){
  log_msg "install python and pip now!!!"
}

install_conda(){
  log_msg "install conda now!!!"
}

config_ssh(){
  if (command_exists ssh) && (command_exists git); then
    log_msg "already setup ssh config, will skip it"
    local insecure_key
    insecure_key=""
    if [[ -f /home/vagrant/.ssh/authorized_keys ]]; then
      insecure_key=$(cat /home/vagrant/.ssh/authorized_keys)
    fi
    echo "setup ssh"
    if [ -f ~/.ssh/github_id_rsa ]; then 
      echo "ssh has been setup!!!"
    else 
      echo "setup ssh for $lsb_dist now!!!"
      export GIT_SSL_NO_VERIFY=1
      rm -rf ~/.ssh
      rm -rf ~/git_settings
      cd ~
      git clone https://gitee.com/lgf1244/git_settings.git
      cd ~/git_settings/.ssh
      # chmod 600 *_id_rsa
      # chmod 600 config
      cp -rp ~/git_settings/.ssh ~
      rm -rf rp ~/git_settings
      # cd ~
      # git clone git@gitee.com:lgf1244/ssh.git
      # rm -rf ~/.ssh 
      # mv ~/ssh ~/.ssh
      cd ~/.ssh
      echo $insecure_key >> authorized_keys
      chmod 600 config authorized_keys *_rsa
      chmod 644 *.pub
    fi
  else
    log_msg "no ssh command found, please install it first!!!"
    install_base_pkgs
  fi
}

config_pip(){
  if command_exists pip; then
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  else
    log_msg "no pip command found, please install it first!!!"
    install_python_and_pip
  fi
}

config_npm(){
  if command_exists npm; then
    npm config set registry https://registry.npm.taobao.org
    if command_exists n; then
      $sudo_flag n stable
    fi
    if command_exists cnpm; then
      $sudo_flag npm i -g cnpm
    fi
    if command_exists yarn; then
      $sudo_flag npm i -g yarn
    fi
    if command_exists pnpm; then
      $sudo_flag npm i -g pnpm
    fi
  else
    log_msg "no npm command found, please install it first!!!"
    install_node_and_npm
  fi
}

config_golang(){
  if command_exists go; then
    log_msg "already setup golang config, will skip it"
  else
    log_msg "no go command found, please install it first!!!"
    install_golang
  fi
}

config_cargo(){
  # if command -v "cargo" >/dev/null 2>&1; then
  if command_exists cargo; then
    echo "cargo settings"
    mkdir -p ~/.cargo
    echo "[source.crates-io]" > ~/.cargo/config
    echo 'registry = "https://github.com/rust-lang/crates.io-index"' >> ~/.cargo/config
    echo 'replace-with = "ustc"' >> ~/.cargo/config
    echo "[source.ustc]" >> ~/.cargo/config
    echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> ~/.cargo/config
    # cargo install lsd
    cargo install lsd sd fd-find broot bottom gping du-dust git-delta nu zellij
  else
    log_msg "no cargo command found, please install it first!!!"
    install_rust_and_cargo
  fi
}

config_conda(){
  if command_exists conda; then
    log_msg "already setup anaconda config, will skip it"
  else
    log_msg "no conda command found, please install it first!!!"
    install_conda
  fi
}

dotfiles_settings(){
  if [[ -d ~/.dotfiles ]]; then
    log_msg "dotfiles already has been doanloaded!!!"
  else
    log_msg "please download dotfiles firstly!!!"
    # git clone git@gitee.com:lgf1244/dotfiles.git ~/.dotfiles
  fi
}

warp_install_with_process_status(){
  process_status "100" "${2}.install ${3}" "start"
  ${1}
  process_status "100" "${2}.install ${3}" "done"
}

main(){
  startTime=$(date +%s)
  $sudo_flag ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  echo 'Asia/Shanghai' | $sudo_flag tee /etc/timezone
  # export DEBIAN_FRONTEND=noninteractive
  # echo "123456" | passwd --stdin root
  echo "root:root" | $sudo_flag chpasswd
  time warp_install_with_process_status   install_base_pkgs           01 base_packages
  time warp_install_with_process_status   install_omb                 02 oh-my-bash
  time warp_install_with_process_status   install_omz                 03 oh-my-zsh
  # time warp_install_with_process_status   install_omf               04 oh-my-fish
  time warp_install_with_process_status   install_omp                 05 oh-my-posh
  time warp_install_with_process_status   install_omt                 06 oh-my-tmux
  time warp_install_with_process_status   install_homebrew            10 homebrew
  if [[ "$DOCKER" = "yes" ]]; then
    time warp_install_with_process_status   install_docker              11 docker
  fi
  if [[ "$POWERSHELL" = "yes" ]]; then
    time warp_install_with_process_status   install_powershell          12 powershell
  fi
  if [[ "$DOTNET" = "yes" ]]; then
    time warp_install_with_process_status   install_dotnet              13 dotnet
  fi
  time warp_install_with_process_status   install_rust_and_cargo      14 rust_and_cargo
  time warp_install_with_process_status   install_golang              15 golang
  time warp_install_with_process_status   install_node_and_npm        16 node_and_npm
  time warp_install_with_process_status   install_python_and_pip      17 python_and_pip
  time warp_install_with_process_status   install_conda               18 conda
  time warp_install_with_process_status   config_ssh                  50 ssh
  time warp_install_with_process_status   config_pip                  51 pip
  time warp_install_with_process_status   config_npm                  52 npm
  time warp_install_with_process_status   config_golang               53 golang
  time warp_install_with_process_status   config_cargo                54 cargo
  time warp_install_with_process_status   config_conda                55 conda
  time warp_install_with_process_status   dotfiles_settings           100 conda
  if [[ "$lsb_dist" = "msys2" ]]; then
    log_msg "msys2"
  fi
  endTime=$(date +%s)
  takeTime=$(( endTime - startTime ))
  echo "-----------------------------------------------------------------------"
  echo "            distribution: $lsb_dist-$sub_lsb_dist                      "
  echo "             environment: $environment                                 "
  echo "                    user: $(whoami)                                    "
  echo "         total cost time: $takeTime seconds                                 "
  echo "-----------------------------------------------------------------------"
  exec zsh
}

main


# docker run -it --rm  ubuntu bash
# docker run -it --name ubuntu --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell -v /etc/localtime:/etc/localtime:ro ubuntu bash
# docker run -it --name debian --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell debian bash -c "bash /root/shell/system-init.sh"
# docker run -it --name ubuntu --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell ubuntu bash -c "bash /root/shell/system-init.sh"
# docker run -it --name kali --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell kalilinux/kali-rolling bash -c "bash /root/shell/system-init.sh"
# docker run -it --name fedora --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell fedora bash -c "bash /root/shell/system-init.sh"
# docker run -it --name rhel7 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell roboxes/rhel7 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name centos-7 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell centos:7 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name centos-8 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell dokken/centos-stream-8 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name centos-9 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell dokken/centos-stream-9 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name rockylinux-9 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell rockylinux:9 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name almalinux-9 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell almalinux:9 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name oraclelinux-9 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell oraclelinux:9 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name openEuler --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell openeuler/openeuler bash -c "bash /root/shell/system-init.sh"
# docker run -it --name anolis --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell openanolis/anolisos bash -c "bash /root/shell/system-init.sh"
# docker run -it --name alpine --rm --privileged -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell alpine sh -c "sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories;apk add bash;bash /root/shell/system-init.sh"
# docker run -it --name archlinux --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell archlinux bash -c "bash /root/shell/system-init.sh"
# docker run -it --name manjaro --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell manjarolinux/base bash -c "bash /root/shell/system-init.sh"
# docker run -it --name opensuse-leap-154 --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell dokken/opensuse-leap-15.4 bash -c "bash /root/shell/system-init.sh"
# docker run -it --name opensuse-tumbleweed --rm --privileged  -v /mnt/d/dev-env/msys64/home/lgf/scripts/shell:/root/shell alvistack/opensuse-tumbleweed bash -c "bash /root/shell/system-init.sh"
# bash /root/shell/system-init.sh




